import {Injectable} from "@angular/core";
import {Observable} from "rxjs";
import {MsgResult} from "../models/msg-result";
import {AppConfig} from "../app.config";
import {CustomHttpClient} from "../tools/http/custom-http-client";
import {CustomHttp} from "../tools/http/custom-http";
/**
 * Created by duqunxing on 2017/3/3.
 */

@Injectable()
export class RequestUtil{

  private client:any;

  constructor(
    private http: CustomHttp,
    private httpClient : CustomHttpClient,
  ){
    if(AppConfig.httpInteceptor){
      this.client= httpClient;
    }else {
      this.client = http;
    }
  }

  get(api:string,params?:string): Observable<MsgResult> | any{
      return this.client.get(api,params);
  }

  post(api:string,params?:string): Observable<MsgResult> | any{
    return this.client.post(api,params);
  }

  put(api:string,params?:string): Observable<MsgResult> | any{
    return this.client.put(api,params);
  }

  delete(api:string,params?:string): Observable<MsgResult> | any{
    return this.client.delete(api,params);
  }

  patch(api:string,params?:string): Observable<MsgResult> | any{
    return this.client.patch(api,params);
  }

  head(api:string,params?:string): Observable<MsgResult> | any{
    return this.client.head(api,params);
  }

  options(api:string,params?:string): Observable<MsgResult> | any{
    return this.client.options(api,params);
  }
  postWithData(api:string,params?:string): Observable<any> | any{
    return this.client.postWithData(api,params);
  }
  getFile(api: string, params?: string): Observable<ArrayBuffer> | any{
      return this.client.getFile(api,params);
  }

}


